<!DOCTYPE html>
<html lang="en">
  <button onclick="method1()">method1</button>
  <button onclick="method2()">setTime</button>
  <button onclick="method3()">继承</button>
  <button onclick="method4()">扩展预算符号</button>

  <body>
    <script type="text/javascript">
      method1 = function () {
        var foo = "test";
        (function () {
          var bar = "1";
          alert(foo + bar);
        })();
        alert(foo + bar);
      };

      method2 = function () {
        // 延时器 执行 0 秒
        for (var i = 0; i < 2; i++) {
          setTimeout(function () {
            // 输出 2 2
            console.log(i);
          }, 0);
        }
        for (let i = 0; i < 2; i++) {
          (function (i) {
            setTimeout(function () {
              // 输出 0 1
              console.log(i);
            }, 0);
          })(i);
        }
      };

      function father() {
        this.num = 935;
        this.work = ["read", "write", "listen"];
      }
      function son() {}
      son.prototype = new father();
      method3 = function () {
        let son1 = new son();
        let son2 = new son();
        son1.num = 117;
        son1.work.pop();
        console.log(son2.num);
        console.log(son2.work);
      };

      method4 = function () {
        let item = { a: 1, b: 2, c: 3, d: 4 };
        let obj1 = { ...item };
        // 对象的合并
        let obj2 = Object.assign({}, item);
      };
    </script>
  </body>
</html>
